//
//  OtherRequestAPI.m
//  CarLoan
//
//  Created by Mac on 2018/10/26.
//  Copyright © 2018年 eduonline. All rights reserved.
//

#import "OtherRequestAPI.h"
#import "NetworkConfig.h"

@interface OtherRequestAPI()

@property (nonatomic ,strong) NSString *baseUrl;

@property (nonatomic ,strong) NSString *theApiKey;

@property (nonatomic ,strong) NSMutableDictionary *argumentsDic;

@property (nonatomic ,assign) RequestMethod methodType;

@end

@implementation OtherRequestAPI

- (instancetype)initWithBaseUrl:(NSString *)baseUrl
                         APIKey:(NSString *)apiKey
                       argument:(NSDictionary *)arguments
                  requestMethod:(RequestMethod)method{
    
    self = [super init];
    
    if (self) {
        
        _theApiKey = @"";
        _baseUrl = @"";
        _argumentsDic = [NSMutableDictionary dictionary];
        _methodType = method;
        
        if ([apiKey length]>0) {
            _theApiKey = apiKey;
        }
        
        if ([baseUrl length]>0) {
            _baseUrl = baseUrl;
        }
        
        if (arguments) {
            [_argumentsDic addEntriesFromDictionary:arguments];
        }
    }
    
    return self;
}

- (id)requestArgument {
    return _argumentsDic;
}


- (NSString *)requestUrl {
    return _theApiKey;
}

- (RequestMethod)requestMethod {
    return _methodType;
}

- (NSString *)baseUrl {
    return _baseUrl;
}

- (NSDictionary *)requestHeaderFieldValueDictionary {
    NSString *token = [NSString stringWithFormat:@"Bearer %@",[UserDefaults objectForKey:@"token"]];
    
    NSMutableDictionary *mtb = [[NSMutableDictionary alloc]initWithDictionary:@{@"Accept-Language":[NetworkConfig sharedConfig].language,
                                   @"brandId":[NetworkConfig sharedConfig].brandID,
                                   @"Authorization":token,
                                   @"deviceType":@"iOS",
                                   @"deviceName":SafeStr([UIDevice currentDevice].name),
                                   @"systemVersion":[[UIDevice currentDevice] systemVersion],
                                   @"Version":[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"],
                                   @"platform":@"business"
                                                                              }];
    NSLog(@"--->request header:%@",mtb);
    //@"Content-Type":@"application/x-www-form-urlencoded"
//    if(_header){
//        [mtb addEntriesFromDictionary:_header];
//    }
    return mtb;
}

@end
